package com.cw.jeeyt.service.converter.system;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.service.bo.system.SystemDatabaseColumnBo;
import com.cw.jeeyt.dao.model.system.SystemDatabaseColumnDo;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * 数据库字段信息转换类
 *
 * @author chenw
 * @date 2019-03-10 13:04:25
 */
public class SystemDatabaseColumnConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static SystemDatabaseColumnBo do2Bo(SystemDatabaseColumnDo model) {
        if (model == null) {
            return null;
        }
        SystemDatabaseColumnBo bo = new SystemDatabaseColumnBo();
        bo.setId(model.getId());
        bo.setTableId(model.getTableId());
        bo.setIsPrimaryKey(model.getIsPrimaryKey());
        bo.setColumnCode(model.getColumnCode());
        bo.setColumnName(model.getColumnName());
        bo.setColumnType(model.getColumnType());
        bo.setColumnLength(model.getColumnLength());
        bo.setColumnPoint(model.getColumnPoint());
        bo.setColumnComment(model.getColumnComment());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static SystemDatabaseColumnDo bo2Do(SystemDatabaseColumnBo bo) {
        if (bo == null) {
            return null;
        }
        SystemDatabaseColumnDo model = new SystemDatabaseColumnDo();
        model.setId(bo.getId());
        model.setTableId(bo.getTableId());
        model.setIsPrimaryKey(bo.getIsPrimaryKey());
        model.setColumnCode(bo.getColumnCode());
        model.setColumnName(bo.getColumnName());
        model.setColumnType(bo.getColumnType());
        model.setColumnLength(bo.getColumnLength());
        model.setColumnPoint(bo.getColumnPoint());
        model.setColumnComment(bo.getColumnComment());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<SystemDatabaseColumnBo> doList2BoList(List<SystemDatabaseColumnDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), SystemDatabaseColumnConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<SystemDatabaseColumnDo> boList2DoList(List<SystemDatabaseColumnBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), SystemDatabaseColumnConverter::bo2Do));
    }
}